//
//  BN_PopAgreementViewController.m
//  BabyNow
//
//  Created by 刘泽琛 on 14-7-18.
//  Copyright (c) 2014年 iMobile. All rights reserved.
//

#import "BN_PopAgreementViewController.h"
#import "BN_UseAgreementView.h"

@interface BN_PopAgreementViewController () {
    BN_UseAgreementView *useAgreementView;
}

@end

@implementation BN_PopAgreementViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    if (IOS7) {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    self.title = @"使用协议";
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithTitle:@"同意" style:UIBarButtonItemStylePlain target:self action:@selector(agreementAction)];
    self.navigationItem.rightBarButtonItem = rightItem;
    self.navigationItem.rightBarButtonItem.enabled = NO;
    
    self.view.backgroundColor = APP_OBJECT_GRAY_COLOR;
    useAgreementView = [[[NSBundle mainBundle]loadNibNamed:@"BN_UseAgreementView" owner:nil options:nil]objectAtIndex:0];
    [useAgreementView setDecelerationRate:0.1];
    useAgreementView.delegate = self;
    switch (MAIN_VERSION) {

        case 6:
            useAgreementView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-44);
            break;
        default:
            
            useAgreementView.frame = CGRectMake(0, 44, SCREEN_WIDTH, FULLSCREEN_HEIGHT-44);

            break;
    }
    useAgreementView.backgroundColor = [UIColor whiteColor];
    [useAgreementView loadHintView];
    [self.view addSubview:useAgreementView];
    [UIView animateWithDuration:1 animations:^{
    } completion:^(BOOL finished) {
        // code...
    }];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView1
{
    CGPoint offset = scrollView1.contentOffset;
    CGRect bounds = scrollView1.bounds;
    CGSize size = scrollView1.contentSize;
    UIEdgeInsets inset = scrollView1.contentInset;
    CGFloat currentOffset = offset.y + bounds.size.height - inset.bottom;
    CGFloat maximumOffset = size.height;
    //当currentOffset与maximumOffset的值相等时，说明scrollview已经滑到底部了。也可以根据这两个值的差来让他做点其他的什么事情
    if((maximumOffset - currentOffset)<40.0)
    {
        self.navigationItem.rightBarButtonItem.enabled = YES;
    }
}

- (void)agreementAction {
    [self dismissViewControllerAnimated:YES completion:NULL];
}

- (void)dealloc
{
    NSLog(@"弹出同意协议释放...");
}
@end
